#version 300 es
precision mediump float;
uniform sampler2D samplerY;
uniform sampler2D samplerU;
uniform sampler2D samplerV;
uniform sampler2D samplerUV;
in int yuvType;
in vec2 v_texcoord;
out vec4 gl_FragColor;
void main() {
    vec4 c = vec4((texture2D(samplerY, v_texcoord).r - 16.0/255.0) * 1.164);
    vec4 U; vec4 V;
    if (yuvType == 0){
        U = vec4(texture2D(samplerU, v_texcoord).r - 128.0/255.0);
        V = vec4(texture2D(samplerV, v_texcoord).r - 128.0/255.0);
    } else if (yuvType == 1){
        U = vec4(texture2D(samplerUV, v_texcoord).r - 128./255.);
        V = vec4(texture2D(samplerUV, v_texcoord).a - 128./255.);
    } else {
        U = vec4(texture2D(samplerUV, v_texcoord).a - 128./255.);
        V = vec4(texture2D(samplerUV, v_texcoord).r - 128./255.);
    }
    c += V * vec4(1.596, -0.813, 0, 0);
    c += U * vec4(0, -0.392, 2.017, 0);
    c.a = 1.0;
    gl_FragColor = c;
} 